﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class DiaDiemDao
    {
        public int LayMa()
        {
            DoixeDataContext DX = new DoixeDataContext();

            int Lable;
            Lable = 0;
            int MA = 0;
            while (Lable == 0)
            {
                IEnumerable<DIADIEM> ddDto;
                ddDto = from dd in DX.DIADIEMs where dd.MaDD == MA select dd;
                if (ddDto.Count() != 0)
                {
                    MA++;
                }
                else
                {
                    Lable = 1;
                }
            }
            return MA;
        }
        public void TiepNhanDD(DIADIEM DD)
        {
            DoixeDataContext DX = new DoixeDataContext();
            DX.DIADIEMs.InsertOnSubmit(DD);
            DX.SubmitChanges();
        }
        public IEnumerable<DIADIEM> LayDiaDiem(int Ma)
        {
            DoixeDataContext DX = new DoixeDataContext();
            IEnumerable<DIADIEM> ddDto;
            ddDto = from dd in DX.DIADIEMs where dd.MaDD == Ma select dd;
            return ddDto;
        }
        public IEnumerable<DIADIEM> TimKiem(string TenDD,string DiaChi,String SoDienThoai,string NguoiLienHe)
        {
            DoixeDataContext DX = new DoixeDataContext();
            IEnumerable<DIADIEM> ddDto;
            ddDto = from dd in DX.DIADIEMs where dd.TenDD.Contains(TenDD)&&dd.DiaChi.Contains(DiaChi)&&dd.SoDT.Contains(SoDienThoai)&&dd.NguoiLienHe.Contains(NguoiLienHe) select dd;
            return ddDto;
        }
    }
}
